package com.sinaapp.kjWeb.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 *auth:徐疆
 *date 2014-1-12 下午4:29:19
 */
public class ConfigUtils {
	private static  ConfigUtils cfu;
	Properties properties;
	Logger logger=LoggerFactory.getLogger(ConfigUtils.class);
	private ConfigUtils(){
		
	}
	public static ConfigUtils getInstance(){
		if(cfu==null){
			synchronized (ConfigUtils.class) {
				if(cfu==null){
					cfu=new ConfigUtils();
					cfu.init();
				}
			}
		}
		return cfu;
	}
	public String getValue(String key){
		return properties.getProperty(key);
	}
	
	public String getValueAndDefault(String key,String defaultStr){
		String v=getValue(key);
		return StringUtil.isBlank(v)?defaultStr:v;
	}
	
	public void init(){
		properties=new Properties();
		InputStream ci=ConfigUtils.class.getResourceAsStream("/config.properties");
		try {
			properties.load(ci);
		} catch (IOException e) {
			logger.error("读取配置文件config.properties 出错",e);
			e.printStackTrace();
		}
	}
}

